//
//  MLoctionCell.m
//  FKGW
//
//  Created by song ce on 2017/2/18.
//  Copyright © 2017年 song ce. All rights reserved.
//

#import "MLoctionCell.h"
#import "BaseNavigationViewController.h"
#import "AddLoctionViewController.h"

@implementation MLoctionCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectionStyle= UITableViewCellSelectionStyleNone;
    self.imageV.hidden = YES;
    // Initialization code
}

-(void)setModel:(LocationModel *)model{
    _model = model;
    self.nameLabel.text =_model.receiverName;
    self.phoneLabel.text = _model.receiverPhone;
    self.locationLabel.text= _model.receiverAddress;
    if([_model.isDefault boolValue]){
        [self.defutBtn setImage:[UIImage imageNamed:@"icon_xuanzhong"] forState:UIControlStateNormal];
    }
    
    if(_model.isNeedToHiddenBottomLine){
        self.bottomLine.hidden = YES;
    }
}
//编辑
- (IBAction)edite:(UIButton *)sender {
    AddLoctionViewController *editeLocationVc= [[AddLoctionViewController alloc]init];
    editeLocationVc.model = _model;
    editeLocationVc.vcName = @"编辑收货地址";
    [[self firstNavigationController]pushViewController:editeLocationVc animated:YES];
}

//删除
- (IBAction)delete:(UIButton *)sender {
    if(self.deleteAddressBlock){
        self.deleteAddressBlock();
    }
}
//设置默认地址
- (IBAction)setLocation:(UIButton *)sender {
    if(self.defultAddressBlock){
        self.defultAddressBlock();
    }
}

-(void)setIsConfirmVc:(BOOL)isConfirmVc{
    _isConfirmVc = isConfirmVc;
    if(_isConfirmVc){
        _butn1.hidden = YES;
         _butn2.hidden = YES;
        _butn3.hidden= NO;
        _seperateLine.hidden = YES;
    }
}

- (IBAction)edite2:(UIButton *)sender {
    AddLoctionViewController *editeLocationVc= [[AddLoctionViewController alloc]init];
    editeLocationVc.model = _model;
    editeLocationVc.vcName = @"编辑收货地址";
    editeLocationVc.isConfirmVc = _isConfirmVc;
    [[self firstNavigationController]pushViewController:editeLocationVc animated:YES];
}
- (BaseNavigationViewController*)firstNavigationController{
    UIResponder *next = self.nextResponder;
    while (next!=nil) {
        if([next isKindOfClass:[BaseNavigationViewController class]]){
            return (BaseNavigationViewController*)next;
        }
        next = next.nextResponder;
    }
    return nil;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
